package kr.saeildamil.androidstudy.ch13;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;

public class WebViewTest extends Activity {
	WebView mWeb;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_webview);
		
	mWeb = (WebView) findViewById(R.id.ch13_webview_web);
	mWeb.setWebViewClient(new MyWebClient());
	WebSettings set = mWeb.getSettings();
	set.setJavaScriptEnabled(true);
	set.setBuiltInZoomControls(true);
	mWeb.loadUrl("http://www.google.com");
	}
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.ch13_webview_go_btn:
			String url;
			EditText addr = (EditText) findViewById(R.id.ch13_webview_address_et);
			url = addr.getText().toString();
			mWeb.loadUrl(url);
			break;
		case R.id.ch13_webview_back_btn:
			if(mWeb.canGoBack()){
				mWeb.goBack();
			}
			break;
		case R.id.ch13_webview_forward_btn:
			if(mWeb.canGoForward()){
				mWeb.goForward();
			}
			break;
		case R.id.ch13_webview_local_btn:
			mWeb.loadUrl("file:///android_asset/test.html");
			break;
		}
	}
	class MyWebClient extends WebViewClient{
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}
}
